/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.webhomesites.locacao.view;

import br.com.webhomesites.locacao.model.ItemLocacaoModel;
import java.awt.Component;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.List;
import javax.swing.JTextField;

/**
 *
 * @author Webhome
 */
public class DevolucaoParcSemPagView extends javax.swing.JDialog implements FocusListener {

    /**
     * Creates new form DevolucaoTotComPagView
     */
    public DevolucaoParcSemPagView(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();     
        
        setLocationRelativeTo(null);
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        painelCentralDTCP = new javax.swing.JPanel();
        btnConfirmar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnRecibo = new javax.swing.JButton();
        labelDataLocacaoAtual = new javax.swing.JLabel();
        txtDataLocacaoAtual = new javax.swing.JTextField();
        txtDiasLocacaoAtual = new javax.swing.JTextField();
        lavelDiasLocacacaoAtual = new javax.swing.JLabel();
        lavelDataPagamento = new javax.swing.JLabel();
        txtDataPrevDevolucaoAtual = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        lavelDiasLocacacaoAtual1 = new javax.swing.JLabel();
        txtDiasLocacaoCalculado = new javax.swing.JTextField();
        txtDataDevolucao = new javax.swing.JTextField();
        lavelDataPagamento1 = new javax.swing.JLabel();
        labelComboProdutos = new javax.swing.JLabel();
        comboProdutos = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        painelCentralDTCP.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Devolução parcial sem pagamento", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.black));

        btnConfirmar.setText("Confirmar");

        btnCancelar.setText("Cancelar");

        btnRecibo.setText("Recibo");
        btnRecibo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReciboActionPerformed(evt);
            }
        });

        labelDataLocacaoAtual.setText("Data Loc.");

        lavelDiasLocacacaoAtual.setText("Dias Loc.");

        lavelDataPagamento.setText("Data Prev. Dev.");

        lavelDiasLocacacaoAtual1.setText("Dias Calculados");

        txtDataDevolucao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDataDevolucaoActionPerformed(evt);
            }
        });

        lavelDataPagamento1.setText("Data Devolução");

        labelComboProdutos.setText("Produto(s)");

        javax.swing.GroupLayout painelCentralDTCPLayout = new javax.swing.GroupLayout(painelCentralDTCP);
        painelCentralDTCP.setLayout(painelCentralDTCPLayout);
        painelCentralDTCPLayout.setHorizontalGroup(
            painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelCentralDTCPLayout.createSequentialGroup()
                .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelCentralDTCPLayout.createSequentialGroup()
                        .addContainerGap(30, Short.MAX_VALUE)
                        .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelCentralDTCPLayout.createSequentialGroup()
                                    .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(painelCentralDTCPLayout.createSequentialGroup()
                                            .addComponent(lavelDataPagamento1)
                                            .addGap(13, 13, 13))
                                        .addComponent(txtDataDevolucao, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(txtDiasLocacaoCalculado, javax.swing.GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)
                                        .addComponent(lavelDiasLocacacaoAtual1)))
                                .addGroup(painelCentralDTCPLayout.createSequentialGroup()
                                    .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(labelDataLocacaoAtual)
                                        .addComponent(txtDataLocacaoAtual, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(lavelDiasLocacacaoAtual)
                                        .addComponent(txtDiasLocacaoAtual, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(lavelDataPagamento)
                                        .addComponent(txtDataPrevDevolucaoAtual, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(labelComboProdutos)
                                .addComponent(comboProdutos, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelCentralDTCPLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, painelCentralDTCPLayout.createSequentialGroup()
                                .addComponent(btnConfirmar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnCancelar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(btnRecibo, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        painelCentralDTCPLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txtDataLocacaoAtual, txtDataPrevDevolucaoAtual, txtDiasLocacaoCalculado});

        painelCentralDTCPLayout.setVerticalGroup(
            painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(painelCentralDTCPLayout.createSequentialGroup()
                .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelDataLocacaoAtual)
                    .addComponent(lavelDiasLocacacaoAtual)
                    .addComponent(lavelDataPagamento))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtDataLocacaoAtual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDiasLocacaoAtual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDataPrevDevolucaoAtual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(painelCentralDTCPLayout.createSequentialGroup()
                        .addComponent(lavelDiasLocacacaoAtual1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDiasLocacaoCalculado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(painelCentralDTCPLayout.createSequentialGroup()
                        .addComponent(lavelDataPagamento1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDataDevolucao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelComboProdutos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(comboProdutos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(painelCentralDTCPLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnConfirmar)
                    .addComponent(btnCancelar)
                    .addComponent(btnRecibo))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        painelCentralDTCPLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {txtDataLocacaoAtual, txtDataPrevDevolucaoAtual, txtDiasLocacaoAtual, txtDiasLocacaoCalculado});

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(painelCentralDTCP, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(painelCentralDTCP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtDataDevolucaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDataDevolucaoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDataDevolucaoActionPerformed

    private void btnReciboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReciboActionPerformed
    this.dispose();        // TODO add your handling code here:
    }//GEN-LAST:event_btnReciboActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DevolucaoParcSemPagView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DevolucaoParcSemPagView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DevolucaoParcSemPagView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DevolucaoParcSemPagView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the dialog
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                DevolucaoParcSemPagView dialog = new DevolucaoParcSemPagView(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnConfirmar;
    private javax.swing.JButton btnRecibo;
    private javax.swing.JComboBox comboProdutos;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel labelComboProdutos;
    private javax.swing.JLabel labelDataLocacaoAtual;
    private javax.swing.JLabel lavelDataPagamento;
    private javax.swing.JLabel lavelDataPagamento1;
    private javax.swing.JLabel lavelDiasLocacacaoAtual;
    private javax.swing.JLabel lavelDiasLocacacaoAtual1;
    private javax.swing.JPanel painelCentralDTCP;
    private javax.swing.JTextField txtDataDevolucao;
    private javax.swing.JTextField txtDataLocacaoAtual;
    private javax.swing.JTextField txtDataPrevDevolucaoAtual;
    private javax.swing.JTextField txtDiasLocacaoAtual;
    private javax.swing.JTextField txtDiasLocacaoCalculado;
    // End of variables declaration//GEN-END:variables

    

    
   


    
    public void packAndShow() {
        //ConfiguracaoInstancias.getDesktop().add(this);
//        try {
//            this.setSelected(true);
//            this.toFront();
//            this.moveToFront();
//        }
//        catch (PropertyVetoException ex) {
//            Logger.getLogger(DevolucaoTotComPagView.class.getName()).log(Level.SEVERE, null, ex);
//        }
// 
   
        
        this.pack();
        this.setVisible(true);
    }

    
    public void clearFields() {
        Component[] componentesPainel;
        componentesPainel = painelCentralDTCP.getComponents();
        for (int j = 0; j < componentesPainel.length; j++) {
            if (componentesPainel[j] instanceof JTextField) {
                JTextField field = (JTextField) componentesPainel[j];
                field.setText("");
            }
        }
    }   
    
    public void enableBtnConfirmar(boolean arg) {
        btnConfirmar.setEnabled(arg);
    }

    
    public void enableBtnCancelar(boolean arg) {
        btnCancelar.setEnabled(arg);
    }

    
    public void enableBtnRecibo(boolean arg) {
        btnRecibo.setEnabled(arg);
    }
    
    public void setBtnConfirmarRequestFocus(boolean arg) {
        btnConfirmar.requestFocus(arg);
    }
    
    
    public void setConfirmarActionListener(ActionListener listener) {
        btnConfirmar.addActionListener(listener);
    }

    
    public void setCancelarActionListener(ActionListener listener) {
        btnCancelar.addActionListener(listener);
    }

    
    public void setReciboActionListener(ActionListener listener) {
        btnRecibo.addActionListener(listener);
    }    
    
    public void focusLost(FocusEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setDiasLocacaoAtual(int diasLocacao) {
        this.txtDiasLocacaoAtual.setText(Integer.toString(diasLocacao));
    }

    
    public int getDiasLocacaoAtual() {
        return Integer.parseInt(this.txtDiasLocacaoAtual.getText().toString());
    }

    
    public void setDataLocacao(String dataLocacao) {
        this.txtDataLocacaoAtual.setText(dataLocacao);
    }

    
    public String getDataLocacao() {
        return this.txtDataLocacaoAtual.getText();
    }

    public void setDataDevolucao(String dataDevolucao) {
        this.txtDataDevolucao.setText(dataDevolucao);
    }

    
    public String getDataDevolucao() {
        return this.txtDataDevolucao.getText();
    }

    
    public void setDataPrevDevolucaoAtual(String dataPrevDevolucaoAtual) {
        this.txtDataPrevDevolucaoAtual.setText(dataPrevDevolucaoAtual);
    }

    
    public String getDataPrevDevolucaoAtual() {
        return this.txtDataLocacaoAtual.getText();
    }

    
    public void setDiasLocacaoCalculado(int diasLocacao) {
        this.txtDiasLocacaoCalculado.setText(Integer.toString(diasLocacao));
    }

    
    public int getDiasLocacaoCalculado() {
        return Integer.parseInt(this.txtDiasLocacaoCalculado.getText());
    }

    public void setListaItensADevolver(List<ItemLocacaoModel> listaItensADevolver) {
        comboProdutos.removeAllItems();
        for (int i = 0; i < listaItensADevolver.size(); i++) // Percorro o Array List com o For aprimorado.  
        {
            this.comboProdutos.addItem(listaItensADevolver.get(i).getDescricaoItem()); // Adiciono os dados.  
        }
    }

    
    public String getNomeProduto() {
        return this.comboProdutos.getSelectedItem().toString();
    }

    @Override
    public void focusGained(FocusEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }
 
}

